file(GLOB root_src ./*.h ./*.cpp)

file(GLOB Collision_src Collision/*.h Collision/*.cpp)

file(GLOB Diagnostic_src Diagnostic/*.h Diagnostic/*.cpp)

file(GLOB PhysicalField_src PhysicalField/*.h PhysicalField/*.cpp)

file(GLOB FieldSolver_src FieldSolver/*.h FieldSolver/*.cpp)

file(GLOB Field_src Field/*.h Field/*.cpp)

file(GLOB Grid_src Grid/*.h Grid/*.cpp)

file(GLOB IO_src IO/*.h IO/*.cpp)

file(GLOB Parallel_src Parallel/*.h Parallel/*.cpp)

file(GLOB Input_src Input/*.h Input/*.cpp)

file(GLOB ParticleSource_src ParticleSource/*.h ParticleSource/*.cpp)

file(GLOB PSI_src PSI/*.h PSI/*.cpp)

file(GLOB Species_src Species/*.h Species/*.cpp)

file(GLOB Tool_src Tool/*.h Tool/*.cpp)

set(src_list ${root_src} ${Collision_src} ${Diagnostic_src} ${PhysicalField_src} ${FieldSolver_src}
${Field_src} ${Grid_src} ${IO_src} ${Parallel_src} ${Input_src} ${ParticleSource_src} ${PSI_src}
${Species_src} ${Tool_src})

include("../tools/envs/cmake_config")


#set(python_file_list Python/pycontrol.py Python/pyinit.py Python/pyprofiles.py)
#set(python_inc_list Python/pycontrol.pyh Python/pyinit.pyh Python/pyprofiles.pyh)

#set(COMMAND pwd OUTPUT_VARIABLE cmake_path)

#foreach(python_file ${python_file_list})
#    execute_process(WORKING_DIRECTORY ${hedpic_root_path}/src COMMAND xxd -i ${python_file} ${python_file}h)
#    message("-- current_path is : " ${python_file})
#endforeach(python_file)

set(inc_dir ${mpich_dir}/include ${SuperLU_dir}/include ${hdf5_dir}/include  ${petsc_dir}/include ${rapidjson_dir}/include ${boost_dir}/include)
set(lib_dir ${gcc_dir}/lib64 ${mpich_dir}/lib ${SuperLU_dir}/lib ${hdf5_dir}/lib ${petsc_dir}/lib ${boost_dir}/lib)


if(${SuperLU_serial} MATCHES "yes")
    add_definitions(-DSuperLU_serial)
endif()

if(${petsc} MATCHES "yes")
    add_definitions(-Dpetsc)
endif()

#dynamic libaray link for boost log
add_definitions(-DBOOST_LOG_DYN_LINK)

#SET(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -Ofast -march=native -flto")
SET(CMAKE_CXX_FLAGS_RELEASE "-std=c++11 -Ofast")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -std=c++11 -no-pie -lpthread -ldl  -lutil -lrt -lm  -Xlinker -export-dynamic")

set(CMAKE_BUILD_TYPE Release)

include_directories("${inc_dir}")
link_directories(${lib_dir})

add_executable(hedpic ${src_list})


target_link_libraries(hedpic -lmpich -lhdf5 -lblas -lsuperlu -lpetsc -lboost_log -lboost_log_setup -lboost_thread -lpthread -lm -lz)

set(CMAKE_INSTALL_PREFIX ${hedpic_install_path})
install(TARGETS hedpic DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
